package com.cmccgz.udacs_landlord_webapp.main.warning.presenters;

import com.cicadamob.contact.api.Utils.StringUtil;
import com.cmccgz.udacs_landlord_webapp.base.ApiService;
import com.cmccgz.udacs_landlord_webapp.bean.ResultBean;
import com.cmccgz.udacs_landlord_webapp.main.warning.contracts.WarningDealContract;
import com.cmccgz.udacs_landlord_webapp.update.StringUtils;

import rx.Subscriber;


public class WarningDealPresenter implements WarningDealContract.Presenter {
    private WarningDealContract.View view;

    public WarningDealPresenter(WarningDealContract.View view) {
        this.view = view;
    }

    @Override
    public void dealWarning(String w_id, String d_phone, String d_result, String d_type, String sn) {
        if (StringUtils.isEmpty(w_id)) {
            view.dealError("请选择处理报障！");
            return;
        }
        if (StringUtils.isEmpty(d_phone)) {
            view.dealError("请选择处理人！");
            return;
        }
        if (StringUtils.isEmpty(d_result)) {
            view.dealError("请输入处理结果！");
            return;
        }
        if (StringUtils.isEmpty(d_type)) {
            view.dealError("请选择处理方式！");
            return;
        }
        if ("1".equals(d_type)&& StringUtil.isEmpty(sn)) {
            view.dealError("请输入sn码！");
            return;
        }
        ApiService.dealWarning(w_id,d_phone,d_result,d_type,sn).subscribe(new Subscriber<ResultBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                view.dealError("处理失败，请稍后再试！");
            }

            @Override
            public void onNext(ResultBean resultBean) {
                if ("0".equals(resultBean.rsmsg.rscode)) {
                    view.dealSuccess();
                }else{
                    view.dealError(resultBean.rsmsg.rsdesc);
                }
            }
        });
    }
}
